/**
 * ViewPictureForm.java
 *
 *
 * $LastChangedBy: allen $
 * $LastChangedDate: 2007-12-11 17:22:48 +0800 $
 * $Revision: 1440 $
 */
package com.myspace.view.picture;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.myspace.domain.Picture;
import com.myspace.domain.PictureComment;
import com.myspace.view.common.Constant;

public class ViewPictureForm extends ActionForm {

	private static final long serialVersionUID = 20071120L;

	private String tag = "";

	private long userId = -1;

	private List<String> tagList;

	private List<Picture> tagPicList;

	// For list picture.
	private int tagPage = 1;

	// For view picture
	private long picId = -1;

	private long prePicId = -1;

	private long nextPicId = -1;

	private Picture picture = null;

	private List<PictureComment> commentList;

	private String viewType = "";

	public long getPicId() {
		return picId;
	}

	public void setPicId(long picId) {
		this.picId = picId;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public List<String> getTagList() {
		return tagList;
	}

	public void setTagList(List<String> tagList) {
		this.tagList = tagList;
	}

	public List<Picture> getTagPicList() {
		return tagPicList;
	}

	public void setTagPicList(List<Picture> tagPicList) {
		this.tagPicList = tagPicList;
	}

	public void setTagPage(int tagPage) {
		this.tagPage = tagPage;
	}

	public int getTagPage() {
		return tagPage;
	}

	public long getPrePicId() {
		return prePicId;
	}

	public void setPrePicId(long prePicId) {
		this.prePicId = prePicId;
	}

	public long getNextPicId() {
		return nextPicId;
	}

	public void setNextPicId(long nextPicId) {
		this.nextPicId = nextPicId;
	}

	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {

		this.tag = "";
		this.picId = -1;
		this.tagPage = 1;
		this.tagList = null;
		this.tagPicList = null;
		this.prePicId = -1;
		this.nextPicId = -1;
		this.commentList = null;
		this.picture = null;
		this.viewType = "";
		this.userId = -1;
	}

	public List<PictureComment> getCommentList() {
		return commentList;
	}

	public void setCommentList(List<PictureComment> commentList) {
		this.commentList = commentList;
	}

	public Picture getPicture() {
		return picture;
	}

	public void setPicture(Picture picture) {
		this.picture = picture;
	}

	public String getViewType() {
		return viewType;
	}

	public void setViewType(String viewType) {
		this.viewType = viewType;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public String getEncodingTag() throws UnsupportedEncodingException {
		return URLEncoder.encode(this.getTag(), Constant.ENCODING);
	}

	public void calculateNavPicId(List<Picture> picList) {
		for (int i = 0; picList != null && i < picList.size(); i++) {
			if (picList.get(i) == null)
				continue;
			if (picture != null
					&& (picture.getId().longValue() == picList.get(i).getId()
							.longValue())) {
				if (i > 0) {
					prePicId = picList.get(i - 1).getId().longValue();
				}
				if (i < picList.size() - 1) {
					nextPicId = picList.get(i + 1).getId().longValue();
				}
				break;
			}
		}
	}

}
